function [ecode, errMsg] = checksiz(sizes, fun)
%CHECKSIZ Test size consistency among input arguments.
%
%   [ECODE, ERRMSG] = checksiz(SIZES, FUN)
%
%   Inputs:
%    SIZES - An Mx2 matrix containing the size of each input argument.
%
%      FUN - The name of the function from which CHECKSIZ is invoked.
%
%   Outputs:
%    ECODE - Specifies if any size consistencies are violated.
%            1 - Yes
%            0 - No
%
%   ERRMSG - Displays an error message as an output (instead of to the command
%                 window) if boundary conditions are not met.
%
%   For example:
%      To check for input argument size consistency in the function FOO which
%      takes the inputs A and B.
%
%      A = rand(5); B = rand(7);
%      [ecode, errMsg] = checksiz([size(A); size(B)], 'FOO')
%
%      ecode =
%           1
% 
%      errMsg =
%      Dimensions of inputs are inconsistent.
%
%   See also CHECKRNG, CHECKTYP.

%   Copyright 1995-2002 The 
%   $Revision: 1.8.2.3 $   $Date: 2008/03/28 15:22:18 $

% Default
ecode = 0;
errMsg = '';

% Note: As of 3/05 the below row/col_index variable do not allow inputs that
% are conflicting in dims pass (i.e. a: 1x2 and b: 2x1).  
% '& sizes(:, 2) ~= 1' was removed. This makes each of our toolbox
% functions more consistent and less problematic.
row_index = find(sizes(:, 1) ~= sizes(1, 1));
col_index = find(sizes(:, 2) ~= sizes(2, 2));

if ~isempty(row_index) || ~isempty(col_index)
    ecode = 1;
    disp(char(32))
    msgHeader = sprintf('??? Error using ==> %s\n', fun);

    errMsg = 'Dimensions of inputs are inconsistent.';

    if nargout <= 1
        fprintf([msgHeader, errMsg, '\n\n'])
    end
end


% [EOF]
